﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using H2.NET.Web.Workflow.Services;
using H2.NET.Business.Core;
using System.Text;
using H2.NET.Web.Workflow.DwzCode;
using H2.NET.Common;
using H2.NET.Web.Workflow.Helpers;
using H2.NET.Web.Management.Config.Service;
using H2.NET.Web.Management.Config.Model;

namespace H2.NET.Web.Management.Config
{
    public partial class Create : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ConfigService _configService = new ConfigService();
            String hd = Request["hd_parentId"];
            var action = AksRequest.GetQueryString("action");
            if (action.Equals("save")) 
            {
                var t_dmp_config = new t_smd_Config();
                t_dmp_config.Name = AksRequest.GetFormString("name");
                t_dmp_config.Value = AksRequest.GetFormString("value");
                t_dmp_config.Seq = AksRequest.GetFormInt("order_xh");
                t_dmp_config.Code = AksRequest.GetFormString("code");
                t_dmp_config.Level = Utils.StrToInt(AksRequest.GetFormString("l_level"), 0);
                if (hd != null && !hd.Equals("0"))
                {
                    t_dmp_config.ParentID = int.Parse(hd);
                }
                _configService.Add(t_dmp_config);
                string rel = Request["rel"];
                if (rel != null && !rel.Equals("0")&&!rel.Equals(""))
                {
                    SuccessMsg("ConfigIndex_" + rel);
                }
                else
                {
                    SuccessMsg("ConfigIndex");
                }
                return;
            }
            else
            {
                int pId = AksRequest.GetQueryInt("pId");
                hd_parentId.Value = pId.ToString();
                if (pId == 0)
                {
                    l_level.Value = "0";
                }
                else 
                {
                    t_smd_Config pConfig = _configService.GetModel(pId);
                    l_level.Value = (pConfig.Level + 1).ToString();
                }
                rel.Value = Request["rel"];
               
            }

        }
    }
}